<table summary="" id="pagehead" cellpadding="0" cellspacing="0" border="0" width="100%">
	<tr>
		<td><h1>客户管理</h1></td>
		<td class="actions">
			<table summary="" cellpadding="0" cellspacing="0" border="0" align="right">
				<tr>
                	<td <?=$this->view_act ?>><a href="?app=customer&mod=customermanage">客户列表</a></td>
					<td <?=$this->add_act ?>><a href="?app=customer&mod=customermanage&opt=add" id="add_table">添加客户</a></td>
					<td <?=$this->edit_act ?>><a href="#">编辑客户</a></td>
				</tr>
			</table>
		</td>
	</tr>
</table>
<?php if($this->opt=='view'): ?>
<script>
$(function(){
	// 删除
    $('img[del]').click(function (){
        var cid = $(this).attr('del');
        var nickname = $(this).attr('nickname');
        if(confirm('删除此客户将会把下属的用户删除，真的要删除'+nickname+'吗？')) {
            $.getJSON('?app=<?php echo APP; ?>&mod=customermanage&opt=delete',{cid:cid},function(data){
                if (data.state <= 0)
                {
                    alert(data.message);
                    return false;
                }
				//dialogMessage(data.message,'green');
				alert(data.message);
                $('tr[wparam='+cid+']').remove();
            });
        }
    });
	
});
</script>
<div class="t_2">
     <div class="fl">客户列表</div>
     <div class="fr add_form"></div>
</div>
<table width="100%" cellpadding="0" cellspacing="0" border="0" class="table1">
       <tr>
            <th class="th0">编号</th>
            <th class="th1">客户名称</th>
            <th class="th0">座机</th>
            <th class="th1">手机</th>
            <th class="th1">邮箱</th>
            <th class="th1">地址</th>
            <th class="th1">注册时间</th>
            <th class="th1">操作</th>
       </tr>
       <?php foreach((array)$this->customers as $customer): ?> 
       <tr wparam="<?php echo $customer['customer_id']; ?>">
            <td><?php echo $customer['customer_id']; ?></td>
            <td><?php echo $customer['customer_name']; ?></td>
            <td><?php echo $customer['tel']; ?></td>
            <td><?php echo $customer['mobile']; ?></td>
            <td><?php echo $customer['email']; ?></td>
            <td><?php echo $customer['address']; ?></td>
            <td><?php echo date('Y-m-d H:i',$customer['created_time']); ?></td>
            <td>
            <?php echo opt('edit','?app=customer&mod=customermanage&opt=edit&cid='.$customer['customer_id'],'title="编辑客户"'); ?>
            <?php echo opt('trash','javascript:;','del="'.$customer['customer_id'].'" nickname="'.$customer['customer_name'].'" title="删除"'); ?>
            <?php echo opt('addcustomer','?app=customer&mod=usermanage&customer_id='.$customer['customer_id'].'&opt=add','title="管理用户"'); ?>
            <?php echo opt('productmanage','?app=customer&mod=recommend&customer_id='.$customer['customer_id'],'title="添加推荐商品"'); ?>
            <?php echo opt('fapiaomanage','?app=customer&mod=fapiao&customer_id='.$customer['customer_id'],'title="发票信息管理"'); ?>
            <?php echo opt('addressmanage','?app=customer&mod=address&customer_id='.$customer['customer_id'],'title="收货地址管理"'); ?>
            </td>
       </tr>
       <?php endforeach; ?>
</table>
<div class="page_num">
     <div class="fl">
        <span></span>
     </div>
     <div class="fr">
        <p class="cpager">
            <?php echo $this->pager; ?>
        </p>
     </div>
</div>
<?php elseif($this->opt=='add'): ?>
<script>
$(function(){
    $('#form').submit(function(){
        // ajax发送数据
        $.post(location.href,$(this).serialize(),function(data){
            if (data.state <= 0)
            {
                $('#'+data.extra).focus();
                alert(data.message);
                return false;
            }
            //dialogMessage(data.message,'green');
			alert(data.message);
			location.href = "?app=customer&mod=customermanage";
        },'json');
        return false;
    });
});
</script>
<div class="edit_tab tab">
<div class="bg1">
<div class="bg2">
      <span rel="info" class="span_now">添加客户</span>
</div>
</div>
</div>
<div >
<table cellspacing="2" cellpadding="2" class="helptable"><tr><td>
<ul>
	<li><b>小提示</b></li>
	<li>(1) <span style="color:red;">红色</span>项为必填项</li>
    <li>(2) 新添加的客户通过审核后才能在客户列表里显示</li>
</ul>
</td></tr>
</table>
</div>
<form id="form">
<div class="post_form" id="info_form">
	<table width="100%" cellpadding="0" cellspacing="0" border="0" class="info_table">
		<tr>
			<td class="td2">客户名称：</td>
			<td><span><input name="customer_name" id="customer_name" value="" /><font color="#848484">不超过10个字符</font></span></td>
		</tr>
		<tr>
			<td class="td1">座机：</td>
			<td><span><input name="tel" id="tel" value="" /><font color="#848484">7或11位纯数字，区号和号码间不能有符号</font></span></td>
		</tr>
        <tr>
			<td class="td1">手机：</td>
			<td><span><input name="mobile" id="mobile" value="" /></span></td>
		</tr>
        <tr>
			<td class="td1">地址：</td>
			<td><span><input name="address" id="address" value="" /></span></td>
		</tr>
        <tr>
			<td class="td1">电子邮箱：</td>
			<td><span><input name="email" id="email" value="" /></span></td>
		</tr>
		<tr>
			<td class="td1">备注：</td>
			<td><textarea name="mark" id="mark"></textarea></td>
		</tr>
		<tr>
			<td colspan="2" style="text-align:center" class="td1">
            	<input type="submit" value="提交"/>
            	<input name="" type="reset" class="btn1" value="重置" />
            </td>
		</tr>
     </table>
</div>
</form>
<?php elseif($this->opt=='edit'): ?>
<script>
$(function(){
    $('#form').submit(function(){
        // ajax发送数据
        $.post(location.href,$(this).serialize(),function(data){
            if (data.state <= 0)
            {
                $('#'+data.extra).focus();
                alert(data.message);
                return false;
            }
			alert(data.message);
			location.href = "?app=customer&mod=customermanage";
            //dialogMessage(data.message,'green');
        },'json');
        return false;
    });
});
</script>

<div class="edit_tab tab">
<div class="bg1">
<div class="bg2">
      <span rel="info" class="span_now">编辑客户</span>
</div>
</div>
</div>
<div >
<table cellspacing="2" cellpadding="2" class="helptable"><tr><td>
<ul>
	<li><b>小提示</b></li>
	<li>(1) <span style="color:red;">红色</span>项为必填项</li>
    <li>(2) 新添加的客户通过审核后才能在客户列表里显示</li>
</ul>
</td></tr>
</table>
</div>
<form id="form">
<div class="post_form" id="info_form">
	<table width="100%" cellpadding="0" cellspacing="0" border="0" class="info_table">
		<tr>
			<td class="td2">客户名称：</td>
			<td><span><input name="customer_name" id="customer_name" value="<?php echo $this->customer['customer_name']; ?>" /><font color="#848484">不超过10个字符</font></span></td>
		</tr>
		<tr>
			<td class="td1">座机：</td>
			<td><span><input name="tel" id="tel" value="<?php echo $this->customer['tel']; ?>" /><font color="#848484">7或11位纯数字，区号和号码间不能有符号</font></span></td>
		</tr>
        <tr>
			<td class="td1">手机：</td>
			<td><span><input name="mobile" id="mobile" value="<?php echo $this->customer['mobile']; ?>" /></span></td>
		</tr>
        <tr>
			<td class="td1">地址：</td>
			<td><span><input name="address" id="address" value="<?php echo $this->customer['address']; ?>" /></span></td>
		</tr>
        <tr>
			<td class="td1">电子邮箱：</td>
			<td><span><input name="email" id="email" value="<?php echo $this->customer['email']; ?>" /></span></td>
		</tr>
		<tr>
			<td class="td1">备注：</td>
			<td><textarea name="mark" id="mark"><?php echo $this->customer['mark']; ?></textarea></td>
		</tr>
		<tr>
			<td colspan="2" style="text-align:center" class="td1">
            	<input type="submit" value="提交"/>
            	<input name="" type="reset" class="btn1" value="重置" />
                <input name="customer_id" type="hidden"  value="<?php echo $this->customer['customer_id']; ?>" />
            </td>
		</tr>
     </table>
</div>
</form>
<?php endif; ?>